package com.infra.micro.oss.controller;

import com.infra.common.resp.PageEx;
import com.infra.common.resp.Response;
import com.infra.micro.oss.domain.service.BizInfoService;
import com.infra.micro.oss.model.req.QueryBizInfoReq;
import com.infra.micro.oss.model.vo.BizFileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/api/oss")
@RestController
@Api(tags = {"业务文件管理服务"})
public class BizInfoController {
    @Resource
    private BizInfoService bizInfoService;

    @ApiImplicitParam(name = "bizId", value = "业务文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @ApiOperation(value = "根据业务文件ID查询文件", notes = "根据业务文件ID查询文件信息", produces = "application/json")
    @GetMapping("/bizInfo/{bizId}")
    public Response<BizFileVO> queryByBizId(@PathVariable("bizId") Long bizId) {
        return bizInfoService.queryByBizId(bizId);
    }

    @ApiImplicitParam(name = "bizId", value = "业务文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @ApiOperation(value = "根据业务文件ID删除文件", notes = "根据业务文件ID删除文件信息", produces = "application/json")
    @DeleteMapping(value = "/bizInfo/{bizId}")
    public Response<Boolean> deleteByBizId(@PathVariable("bizId") Long bizId) {
        return bizInfoService.deleteByBizId(bizId);
    }

    @ApiImplicitParam(name = "bizIds", value = "业务文件ID列表", dataType = "Long", dataTypeClass = Long.class, allowMultiple = true, paramType = "body", required = true)
    @ApiOperation(value = "根据业务文件ID集合查询文件", notes = "根据业务文件ID集合查询文件信息", produces = "application/json")
    @PostMapping("/bizInfos")
    public Response<List<BizFileVO>> queryByBizIds(@RequestBody List<Long> bizIds) {
        return bizInfoService.queryByBizIds(bizIds);
    }

    @ApiImplicitParam(name = "bizIds", value = "业务文件ID列表", dataType = "Long", dataTypeClass = Long.class, allowMultiple = true, paramType = "body", required = true)
    @ApiOperation(value = "根据业务文件ID集合删除文件", notes = "根据业务文件ID集合删除文件信息", produces = "application/json")
    @DeleteMapping("/bizInfos")
    public Response<Boolean> deleteByBizIds(@RequestBody List<Long> bizIds) {
        return bizInfoService.deleteByBizIds(bizIds);
    }

    @ApiOperation(value = "根据条件分页查询业务文件列表", notes = "根据条件分页查询业务文件列表", produces = "application/json")
    @GetMapping(value = "/bizInfo/list")
    public Response<PageEx<BizFileVO, QueryBizInfoReq>> queryByPage(QueryBizInfoReq req) {
        return bizInfoService.queryByPage(req);
    }
}
